package db

import (
	"github.com/jinzhu/gorm"
	_ "github.com/jinzhu/gorm/dialects/mysql"
)

type OperateTables struct {
}

func (receiver OperateTables) CreateTable() {
	db, err := gorm.Open("mysql", "root:root1234@tcp(127.0.0.1:3306)/ticket?charset=utf8mb4&parseTime=True&loc=Local")
	if err != nil {
		panic("failed to connect database")
	}
	defer db.Close()

	// 案件表
	hasCase := db.HasTable(&Case{})
	if !hasCase {
		db.CreateTable(&Case{})
	}

	// 资料管理表
	dataManage := db.HasTable(&DataManage{})
	if !dataManage {
		db.CreateTable(&DataManage{})
	}

	// 文书管理表
	docGen := db.HasTable(&DocGen{})
	if !docGen {
		db.CreateTable(&DocGen{})
	}

	// 调解指导
	mediaGuide := db.HasTable(&MediaGuide{})
	if !mediaGuide {
		db.CreateTable(&MediaGuide{})
	}

	// 庭审指导
	trialGuide := db.HasTable(&TrialGuide{})
	if !trialGuide {
		db.CreateTable(&TrialGuide{})
	}

	// 订单管理
	orderManage := db.HasTable(&OrderManage{})
	if !orderManage {
		db.CreateTable(&OrderManage{})
	}

}
